package com.easyfun.healthmagicbox.comm.json;

import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.HealthInputData;

public class HealthInputDataJsonWrapper <T extends JsonWrapper,E> 
		extends AbstractJsonWrapper<T,HealthInputData>
{
	
	public HealthInputDataJsonWrapper(HealthInputData pp)
	{
		super(pp);
	}

	public HealthInputDataJsonWrapper()
	{
		
	}
 
    public void deserializeFromObj(JSONObject obj) throws JSONException {

    	if (mpp==null)
    		mpp = new HealthInputData();
    	mpp.setPersonID(obj.getString("personID"));
    	if (obj.isNull("id"))
    	{
    		mpp.setSyncid(Integer.valueOf(0));
    	}else
    		mpp.setSyncid(obj.getInt("id"));
    	mpp.setValueData(obj.getString("valueData"));
    	mpp.setValueLocation(obj.getString("valueLocation"));
    	if (obj.isNull("valueTime"))
    	{
    		mpp.setValueTime(Long.valueOf(0));
    	}else
    		mpp.setValueTime(Long.valueOf(obj.getString("valueTime")));
    	mpp.setValueType(obj.isNull("valueType")?Integer.valueOf(0):obj.getInt("valueType"));
    }
 
    
 
    public JSONObject serializeToObj() throws JSONException {
        JSONObject serializedObj = new JSONObject();
        serializedObj.put("clientid", mpp.getId());
        serializedObj.put("personID", mpp.getPersonID());
        serializedObj.put("valueData", mpp.getValueData());
        serializedObj.put("valueLocation", mpp.getValueLocation());
        serializedObj.put("valueTime", mpp.getValueTime());
        serializedObj.put("valueType", mpp.getValueType());
 
        return serializedObj;
    }
   
}
